﻿@inject DialogService dialogService

<RadzenStack Gap="1rem">
    <!-- Issue datetime -->
    <RadzenFormField Text="@Global.IssueDateTime" Variant=Variant.Outlined>
        <ChildContent>
            <RadzenDatePicker @bind-Value="@Form.IssueDateTime"></RadzenDatePicker>
        </ChildContent>
        <Helper>
            <RadzenText TextStyle="TextStyle.Caption">@Global.IssueDateTimeHelper</RadzenText>
        </Helper>
    </RadzenFormField>
    <!-- Expiration datetime -->
    <RadzenFormField Text="@Global.ExpirationDateTime" Variant=Variant.Outlined>
        <ChildContent>
            <RadzenDatePicker @bind-Value="@Form.ExpirationDateTime"></RadzenDatePicker>
        </ChildContent>
        <Helper>
            <RadzenText TextStyle="TextStyle.Caption">@Global.ExpirationDateTimeHelper</RadzenText>
        </Helper>
    </RadzenFormField>
    <!-- Subject -->
    <RadzenFormField Text="@Global.Subject" Variant=Variant.Outlined>
        <ChildContent>
            <RadzenTextBox @bind-Value="@Form.Subject"></RadzenTextBox>
        </ChildContent>
        <Helper>
            <RadzenText TextStyle="TextStyle.Caption">@Global.SubjectHelper</RadzenText>
        </Helper>
    </RadzenFormField>
    <!-- Credential identifier -->
    <RadzenFormField Text="@Global.CredentialId" Variant=Variant.Outlined>
        <ChildContent>
            <RadzenTextBox @bind-Value="@Form.CredentialId"></RadzenTextBox>
        </ChildContent>
        <Helper>
            <RadzenText TextStyle="TextStyle.Caption">@Global.CredentialIdHelper</RadzenText>
        </Helper>
    </RadzenFormField>
    <div>
        <RadzenButton Click=@((evt) => Save()) Variant="Variant.Text">@Global.Save</RadzenButton>
    </div>
</RadzenStack>

@code {
    record IssueCredentialForm
    {
        public DateTime IssueDateTime { get; set; }
        public DateTime? ExpirationDateTime { get; set; }
        public string Subject { get; set; }
        public string CredentialId { get; set; }
    }

    IssueCredentialForm Form { get; set; } = new IssueCredentialForm();

    void Save()
    {
        dialogService.Close(new CredentialIssuer.Domains.Credential
        {
            IssueDateTime = Form.IssueDateTime,
            ExpirationDateTime = Form.ExpirationDateTime,
            Subject = Form.Subject,
            CredentialId = Form.CredentialId
        });
    }
}
